<%@page import="interfaces.DALException"%>
<%@page import="java.awt.print.Book"%>
<%@page import="org.apache.jasper.tagplugins.jstl.core.ForEach"%>
<%@ page language="java" 
		 contentType="text/html; charset=US-ASCII"
 	     pageEncoding="US-ASCII" 
 	     import="dto_objects.BookDTO,java.util.List"
%>
<%String login = 
		"<form action=\"LoginServlet\">"+
		"<table align=right><tr><td>"+
		"Username</td><td><input style=\"width: 150px;\" type=\"text\" name=\"un\"/><br>"+
		"</td></tr><tr><td>"+
		"Password</td><td><input style=\"width: 100px;\" type=\"password\" name=\"pw\"/>"+
		"<input style=\"width: 50px;\" type=\"submit\" value=\"submit\">"+
		"</td></tr></table>"+
		"</form><br>";
%>
<jsp:useBean id="func" class="Function.FunctionWEB" scope="session"/> 
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
		<title>Template for Table</title>
		<link rel="stylesheet" type="text/css" href="style.css">
	</head>
<body>

<div id=main>
	<div id=header>
		<div style="float: left;"><p style="margin:10px;font-size:40px">Bibliotek</p></div>
		<div style="float: right;">
			<%	
			if(session.getAttribute("currentSessionUser") == null){
				session.setAttribute("userMENU", login);
			}
			%>
			${userMENU}
			<%out.print(func.getClass().getName());%>
		</div>
	</div>
	<div id=contianer>
	<div id=content>
		<form action="TableTemplate.jsp">
			Please enter publisher id		
			<input type="text" name="pubID"/><br>
			<input type="submit" value="submit">	
		</form>
<%
if(null != request.getParameter("pubID") && "" != request.getParameter("pubID")){
	try{
		int id = Integer.parseInt(request.getParameter("pubID"));
		List<BookDTO> Booklist = func.getBookListByPublisherID(id);
		if(Booklist == null)
			throw new NullPointerException();
		out.print("<table>");
		out.print("<th>Title</th><th>Publisher</th>");
		for(BookDTO temp: Booklist){
			out.print("<tr>");
			out.print("<td>" + temp.getTitle() + "</td>");
			out.print("<td>" + temp.getPublisher().getPublisher_name() + "</td>");
			out.print("</tr>");
		}
		out.print("</table>");
	}catch(NumberFormatException e){
		out.print(e);
	}catch(NullPointerException e){
		out.print(e);
	}
}	
%>
<a href="TableTemplate.jsp">MENU1</a><br>
	</div>
	<div id=menu>
		<a href="TableTemplate.jsp">MENU1</a><br>
	</div>
	</div>
	<div id=footer>
	BOTTOM
	</div>
</div>



</body>
</html>